Page({
  data: {
    schema:[
    ],
    formData:{
    },
    title: '',
    result: '',
    remark: '',
    apiName: '', 
    shareTicket:null
  },

  onLoad(options) {
      wx.setNavigationBarTitle({
        title: options.title,
      })
      
      this.setData({
        title: options.title,
        zh:options.zh,
        remark: options.remark,
        webUrl: options.webUrl
      })    
      const tick = wx.getEnterOptionsSync()
      this.data.shareTicket = tick.shareTicket
    console.log(this.data.shareTicket)
  },
  choose1(e){
    console.log(e)
    let that = this
    wx.updateShareMenu({
      withShareTicket: true,
      success (res) { 
        console.log(res)
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname 
        })
      },fail (err) {
        console.log(err)
        that.setData({
          result: err,
          apiName: e.currentTarget.dataset.apiname 
        })
      }
    })
  },
  choose2(e){
    let that = this
    wx.showShareMenu({
      withShareTicket: true,
      menus: ['shareAppMessage', 'shareTimeline'],
      success (res) { 
        console.log(res)
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname 
        })
      },fail (err) {
        console.log(err)
        that.setData({
          result: err,
          apiName: e.currentTarget.dataset.apiname 
        })
      }
    })
  },
  choose3(e){
    let that = this
    wx.downloadFile({
      url: 'https://product.lvcampaign.com/attached/107/images/2025-08-19/804fa5dd3f2544158904759b61d491b1.png',
      success: (res) => {
        console.log(res)
        wx.showShareImageMenu({
          path: res.tempFilePath,
          success (res1) { 
            console.log(res1)
            that.setData({
              result: res1,
              apiName: e.currentTarget.dataset.apiname 
            })
          },fail (err) {
            console.log(err)
            that.setData({
              result: err,
              apiName: e.currentTarget.dataset.apiname 
            })
          }
        })
      }
    })
  },
  choose4(e){
    let that = this
    // callback 写法
   wx.downloadFile({
    url: 'https://product.lvcampaign.com/attached/107/videos/2025-08-20/9d2ed0c1d3954ec5a6c3cca43009a78b.mp4', // 下载url
    success (res) {
      // 下载完成后转发
      wx.shareVideoMessage({
        videoPath: res.tempFilePath,
        success (res1) { 
          console.log(res1)
          that.setData({
            result: res1,
            apiName: e.currentTarget.dataset.apiname 
          })
        },fail (err) {
          console.log(err)
          that.setData({
            result: err,
            apiName: e.currentTarget.dataset.apiname 
          })
        }
      })
    }
  })
  },
  choose5(e){
    let that = this
    wx.shareToOfficialAccount({
      title: '标题',
      content: '正文',
      tags: ['标签1', '标签2'],
      success (res) { 
        console.log(res)
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname 
        })
      },fail (err) {
        console.log(err)
        that.setData({
          result: err,
          apiName: e.currentTarget.dataset.apiname 
        })
      }
    })
  },
  choose6(e){
    let that = this
    wx.downloadFile({
      url: 'https://www.cdeledu.com/OtherItem/miniPrivacy/agreement_chinaacc_wx.docx', // 下载url
      success (res) {
        console.log(res)
        // 下载完成后转发
        wx.shareFileMessage({
          filePath: res.tempFilePath,
          success (res1) { 
            console.log(res1)
            that.setData({
              result: res1,
              apiName: e.currentTarget.dataset.apiname 
            })
          },fail (err) {
            console.log(err)
            that.setData({
              result: err,
              apiName: e.currentTarget.dataset.apiname 
            })
          }
        })
      }
    })
  },
  choose7(e){
    let that = this
    wx.hideShareMenu({
      menus: ['shareAppMessage', 'shareTimeline'],
      success (res) { 
        console.log(res)
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname 
        })
      },fail (err) {
        console.log(err)
        that.setData({
          result: err,
          apiName: e.currentTarget.dataset.apiname 
        })
      }
    })
  },
  choose8(e){
    let that = this
    if (!that.data.shareTicket) {
      wx.showToast({
        title: '没有分享凭证',
        icon: 'none'
      })
      return
    }
    wx.getShareInfo({
      shareTicket: that.data.shareTicket,
      success (res) { 
        console.log(res)
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname 
        })
      },fail (err) {
        console.log(err)
        that.setData({
          result: err,
          apiName: e.currentTarget.dataset.apiname 
        })
      }
    })
  },
  choose9(e){
    let that = this
    if (!that.data.shareTicket) {
      wx.showToast({
        title: '没有分享凭证',
        icon: 'none'
      })
      return
    }
    wx.authPrivateMessage({
      shareTicket: that.data.shareTicket,
      success (res) { 
        console.log(res)
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname 
        })
      },fail (err) {
        console.log(err)
        that.setData({
          result: err,
          apiName: e.currentTarget.dataset.apiname 
        })
      }
    })
  }
})